<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>CK宠物网  个人空间  认证买家资格</title>
    <jsp:include page="top_utils.jsp"></jsp:include>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/myplace.css"/>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/myspace.css">
	
	
  </head>
  
  <body>
 	<!-- 头部-->
	<div class="headnav">
		<div class="topBar">
			<div class="topBarL">
				<jsp:include page="logo.jsp"></jsp:include>
				<div class="nav">
					<ul>
						<li>
							<a href="${pageContext.request.contextPath }/">首页</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/news/">新闻</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/adopt/">领养</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/knowledge/">知识</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/shopping/">商城</a>
						</li>
					</ul>
				</div>
			</div>

			<jsp:include page="topBarR.jsp"></jsp:include>
		</div>
	</div>
 	
	<div id="main" style="background:url('/dogstore/images/${user.backimg}')  no-repeat center top;">
	  <jsp:include page="my_top.jsp"></jsp:include>
	  
	  <div class="layout-body">
	    <div class="w960  clf">   
	      <div class="m_main">
	        <div class="inner centers_mr"> 
	        	<!-- 如果没有通过申请 -->
	     		<c:if test="${user.issale_power == 0 }">	
	     			<div class="public_m2">你没有权限</div>
	     			<button class="layui-btn" onclick="javascript:history.back(-1);">返回个人主页</button>
	     		</c:if>
	     		
	     		<!-- 如果已经通过申请 -->
	     		<c:if test="${user.issale_power == 1 }">
	     			<fieldset class="layui-elem-field site-demo-button">
	     				<legend>发布领养</legend>
					    <a class="layui-btn layui-btn-small" href="${pageContext.request.contextPath }/user/myspace">返回个人主页</a>
					    <a class="layui-btn layui-btn-small" onclick="javascript:history.back(-1);">返回上一步</a>
					  
					  	<!-- 填写发布信息 -->
					  	<br/>
					  	<br/>
					  	<blockquote class="layui-elem-quote">
						  	带*号内容不能为空!</a>
						</blockquote>
					  	<br/>
					  	<br/>
					  	<form class="layui-form layui-form-pane" id="form" action="">
					  		<!-- 标题 -->
					  		<div class="layui-form-item">
							    <label class="layui-form-label">*标题</label>
							    <div class="layui-input-block">
							      <input type="text" name="title" id="d_title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
							    </div>
							</div>
							
							<!-- 萌宠昵称 -->
					  		<div class="layui-form-item">
							    <label class="layui-form-label">昵称</label>
							    <div class="layui-input-block">
							      <input type="text" name="petname" id="petname"  autocomplete="off" placeholder="请输入萌宠昵称" class="layui-input">
							    </div>
							</div>
							
							<!-- 萌宠年龄 -->
					  		<div class="layui-form-item">
							    <label class="layui-form-label">年龄</label>
							    <div class="layui-input-block">
							      <input type="text" name="petage" id="petage" autocomplete="off" placeholder="请输入萌宠年龄(可不填)" class="layui-input">
							    </div>
							</div>
							
							<!-- 类型 -->
							<div class="layui-form-item">
							    <label class="layui-form-label">*类型</label>
							    <div class="layui-input-block">
							      <select name="dogtype_id" id="dogtype_id">
							        <option value="0" selected="">阿拉斯加</option>
							        <option value="1">中华田园犬</option>
							        <option value="2">边境牧羊</option>
							        <option value="3">斗牛犬</option>
							        <option value="4">英国长毛</option>
							        <option value="5">英国短毛</option>
							        <option value="6">波斯喵</option>
							        <option value="7">家猫</option>
							      </select>
							    </div>
							</div>
							
							<!-- 宠物颜色 -->
							<div class="layui-form-item">
							    <label class="layui-form-label">颜色</label>
							    <div class="layui-input-block">
							      <select name="petcolor" id="petcolor">
							      	<option value="" selected="">可不选</option>
							        <option value="red" style="background: #fff;" >red</option>
							        <option value="blue" style="background: blue;" >blue</option>
							        <option value="green" style="background: green;" >green</option>
							        <option value="black" style="background: black;" >black</option>
							        <option value="white" style="background: white;" >white</option>
							        <option value="yellow" style="background: yellow;" >yellow</option>
							      </select>
							    </div>
							</div>
							
							<!-- 现主人大体地址 -->
							<div class="layui-form-item">
							    <label class="layui-form-label">*地址</label>
							    <div class="layui-input-block">
							      <input type="text" name="address" lay-verify="required" id="address" autocomplete="off" placeholder="请输入大题地址" class="layui-input">
							    </div>
							</div>
							
							<!-- 性别 -->
							<div class="layui-form-item" pane="">
							    <label class="layui-form-label">性别</label>
							    <div class="layui-input-block">
							      <input type="radio" name="petsex" value="1" title="雄" checked="">
							      <input type="radio" name="petsex" value="0" title="雌">
							    </div>
							</div>
							
							<!-- 添加封面 -->
							<input type="file" name="file" class="layui-upload-file" lay-title="添加封面">
							<br/>
							<br/>
							
							<!-- 详细介绍 -->
							<div class="layui-form-item layui-form-text">
							    <label class="layui-form-label">*详细介绍</label>
							    <div class="layui-input-block">
							      <textarea class="layui-textarea layui-hide" lay-verify="required" name="a_content" id="a_content"></textarea>
							    </div>
							</div>
							
							<button type="reset" class="layui-btn" > 重 置 </button>
							<a class="layui-btn"  id="sub">立即发布</a>
							
					  	</form>
					</fieldset>
	     		</c:if>
	        </div>
	      </div>
	      
	    </div>
	  </div>
	</div>
	
	<jsp:include page="footer.jsp"></jsp:include>
  </body>
  
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/my_adopt.css">
  <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/head.js"></script>
  <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/util.js"></script>
  	<script>
  		layui.use(['layedit'], function(){
			layedit = layui.layedit; 
		  
		  	//创建一个编辑器
		  	editIndex = layedit.build('a_content');
		  
		  	$("#sub").on("click",function(){
	  			//1.非空校验
				var title = $("#d_title").val();
				var dogtype_id = $("#dogtype_id").val();
				var address = $("#address").val();
				if($.isNull(title)){
					$("#title").focus();
					layer.tips("带*信息不能为空!-标题", "#sub",{tipsMore: true,tips: [2, '#78BA32']});
					return;
				}
				if($.isNull(dogtype_id)){
					$("#dogtype_id").focus();	
					layer.tips("带*信息不能为空-类型!", "#sub",{tipsMore: true,tips: [2, '#78BA32']});
					//layer.msg("信息不能为空",{shift:6});
					return;
				}
				if($.isNull(address)){
					$("#address").focus();	
					//layer.msg("信息不能为空",{shift:6});
					layer.tips("带*信息不能为空!-地址", "#sub",{tipsMore: true,tips: [2, '#78BA32']});
					return;
				}
				layer.msg("111", {shift: 1});
				var html = layedit.getContent(editIndex);
				var text = layedit.getText(editIndex); 
				var petname = $("#petname").val();
				var petage = $("#petage").val();
				var petsex = $("input[name='petsex']:checked").val();
				var petcolor = $("#petcolor").val();
	    		$.ajax({
	    			type:"post",
	    			url:"/dogstore/adopt/add_adopt", 
	    			async:false,  
		    		data:{
		    			title:title,
		    			dogtype_id:dogtype_id,
		    			address:address,
		    			petname:petname,
		    			petage:petage,
		    			petsex:petsex,
		    			petcolor:petcolor,
		    			html:html,
		    			content:text
		    		},
		    		success:function(error){
		    			if (error == '0') {
		    				layer.tips("发布领养信息成功！", "#sub",{tipsMore: true,tips: [2, 'green']});
		    				//layer.msg("发布领养信息成功！", {shift: 1});
		    				setTimeout(function (){
								//关闭弹窗
								window.location.href="/dogstore/user/myadopt";
							},1500);
		    			}else{
		    				layer.tips("发布领养信息失败！500", "#sub",{tipsMore: true,tips: [2, 'red']});
		    				//layer.msg("数据添加失败!请联系prince!", {shift: 6});
		    				return false;
		    			}
		    		},error:function(){
						//layer.msg("发布提交失败!请联系prince..",{shift: 6});
						layer.tips("提交失败!请联系prince..", "#sub",{tipsMore: true,tips: [2, 'red']});
						return false;
					}
		    	},"json");	
	  		});
		});
  		
  		window.onload=function (){
  			if(${user == null}){
  				if(user.issale_power == null || user.issale_power == 0){
  					layer.msg("你没有权限!",{shift: 6});
					setTimeout(function (){
						window.location.href="/dogstore/";
					},1500);
  				}
  				layer.msg("你未登录!",{shift: 6});
				setTimeout(function (){
					window.location.href="/dogstore/";
				},1500);
  			}
  		};
		
		layui.use('upload', function(){
		  layui.upload({
		    url: '' //上传接口
		    ,success: function(res){ //上传成功后的回调
		      console.log(res);
		    }
		  });
		  
		  layui.upload({
		    url: '/test/upload.json'
		    ,elem: '#test' //指定原始元素，默认直接查找class="layui-upload-file"
		    ,method: 'get' //上传接口的http类型
		    ,success: function(res){
		      LAY_demo_upload.src = res.url;
		    }
		  });
		});
  </script>
</html>
